package epay18

import (
	"crypto/md5"
	"encoding/hex"
	"github.com/go-resty/resty/v2"
)

type HttpClient struct {
	cli             *resty.Client
	MerchantCode    string
	MD5Key          string
	Host            string
	NotifyUrlPrefix string
}

var Hc *HttpClient

func InitHttpClient(merchantCode, md5Key, host, notifyUrlPrefix string) {
	if Hc != nil {
		return
	}
	Hc = &HttpClient{
		cli:             resty.New(),
		MerchantCode:    merchantCode,
		MD5Key:          md5Key,
		Host:            host,
		NotifyUrlPrefix: notifyUrlPrefix,
	}
}

func Md5v(str string) string {
	h := md5.New()
	h.Write([]byte(str))
	return hex.EncodeToString(h.Sum(nil))
}
